#include "gwbase/base/countdown_latch.h"

#include <assert.h>

namespace dicom {

void CountdownLatch::Down() 
{
  LockGuard lock(mu_);
  --remain_;
  assert (remain_ >= 0);

  if (remain_ == 0)
    cond_.Broadcast();
}

void CountdownLatch::Wait() {
  LockGuard lock(mu_);
  while (remain_ > 0) 
    cond_.Wait();
}

}
